package com.xu.mvc.controller;

import com.xu.mvc.bean.User;
import org.springframework.http.RequestEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HttpController {

    @RequestMapping("/testRequestBody")
    public String testRequestBody(@RequestBody String requestBody){
        System.out.println(requestBody);
        return "success";
    }

    @RequestMapping("/testRequestEntity")
    public String testRequestEntity(RequestEntity<String> requestEntity){
        // 当前 requestEntity 表示整个请求报文的信息
        System.out.println("requestHeader:"+requestEntity.getHeaders());
        System.out.println("requestBody:"+requestEntity.getBody());
        return "success";
    }

    @ResponseBody
    @RequestMapping("/testResponseBody")
    public String testResponseBody(){
        return "success";
    }

    @ResponseBody
    @RequestMapping("/testResponseUser")
    public User testResponseUser(){
        return new User("平谷一点红", 32, "tfu@163.com", 123);
    }

    @ResponseBody
    @RequestMapping(value = "/testAjax", method = RequestMethod.POST)
    public String testAjax(String username, String password){
        System.out.println("username: " + username + ", password: " + password);
        return "hello, ajax";
    }

}
